<template>
	<view class="container">
		<navBar title="施工巡视记录" @goBack="uni.navigateBack()"></navBar>
		

		<!-- #ifdef APP-PLUS || H5 -->
		<view class="conditional-acceptance-list" :style="{height: `calc(100% - ${systemInfo.navbarHeight || 0}px - ${systemInfo.stateHeight || 0}px - ${systemInfo.bottomHeight || 0}px)`}">
		<!-- #endif -->
		<!--  #ifdef MP-WEIXIN -->
		<view class="conditional-acceptance-list" :style="{height: `calc(100% - ${systemInfo.bottomHeight || 0}px)`}">
		<!-- #endif -->
			<view class="tab">
				<view @click="changeTabIndex(0)" :class="[tabIndex === 0 ? 'active' : '']">待处理</view>
				<view @click="changeTabIndex(1)" :class="[tabIndex === 1 ? 'active' : '']">填报记录</view>
			</view>
			
			<view class="search-content">
				<view class="search">
					<u-icon name="search" color="#a7aebd" size="26"></u-icon>
					 <u--input @change="search" v-model="keyword" placeholder="请输入施工部位、项目名、桩号、填报人" border="surround" :clearable="false" :customStyle="{border: 'none'}"></u--input>
				</view>
				<view @click="pickerShow = true"  class="option" v-if="tabIndex === 0">
					<view>{{ currentTypeStr }}</view>
					<u-icon name="arrow-down" color="#2f80ed" size="18"></u-icon>
				</view>
			</view>
			
			<scroll-view @scrolltolower="scrolltolower" class="scroll-view" scroll-y>
				<view>
					<view v-for="(item, index) in constructionPlanList" :key="index" class="item-content" @click="goToSavePage(item)">
						<view class="title">
							<view  class="state" :class="{'blue':item.state === '进行中', 'orange':item.state === '待填报', 'light-blue':item.state === '已填报'}">{{ item.state }}</view>
							<view class="text-overflow">{{ item.code }}  施工巡视记录</view>
						</view>
						<view class="date">
							<u-icon name="clock" color="#6a819e" size="14"></u-icon>
							<view class="date-text">施工开始：{{ getDate2(item.startTime) }}</view>
						</view>
						<view class="date">
							<u-icon name="clock" color="#6a819e" size="14"></u-icon>
							<view class="date-text">施工结束：{{ getDate2(item.endTime) }}</view>
						</view>
					</view>
					<u-empty v-if="!constructionPlanList.length" mode="data" text="数据为空" icon="http://cdn.uviewui.com/uview/empty/data.png"></u-empty>
				</view>
			</scroll-view>
		</view>	
		<u-picker :show="pickerShow" :columns="columns" keyName="label" @confirm="confirmPicker" @cancel="pickerShow = false"></u-picker>
	</view>
</template>

<script>
	import { handleFormatDate } from "@/utils/date.js"
	import { getSystemHeightInfo } from "@/utils/common.js"
	import { mjsConstructionInspectionRecord_list } from "@/api/mjs.js"
	import mixins from "@/utils/mixins.js"
	export default {
		mixins:[mixins],
		data() {
			return {
				tabIndex: 0,
				keyword: '',
				paging: {
					pageNum: 1,
					pageSize: 10,
					total: 0
				},
				constructionPlanList: [],
				currentTypes: [],
				currentTypeStr: '全部',
				systemInfo: {},
				code: '',
				pickerShow: false,
				columns: [
					[
						{ label: '全部', value: [0,1]},
						{ label: '进行中', value: [1]},
						{ label: '待填报', value: [0]}
					]
				],
			}
		},
		onLoad(options) {
			this.code = options.code
			this.systemInfo = getSystemHeightInfo()
		},
		mounted() {
			this.search()
		},
		methods: {
			goToSavePage(obj) {
				
				uni.navigateTo({
					url:`/subpackage-mjs/pages/constructionInspectionRecord/addNewRecord?id=${obj.mjsDailyMissionId}&pbId=${obj.pbId}&state=${obj.state}&updateId=${obj.id ? obj.id : ''}`
				})
			},
			confirmPicker(event) {
				console.log(event, '00')
				this.pickerShow = false
				this.currentTypes = event.value[0].value
				this.currentTypeStr = event.value[0].label
				this.search()
			},
			changeTabIndex(index) {
				if (this.tabIndex === index) {
					return
				}
				this.tabIndex = index
				this.search()
			},
			scrolltolower() {
				if (this.paging.pageNum * this.paging.pageSize < this.paging.total) {
					this.paging.pageNum++
					this.getConstructionPlanArray()
				}
			},
			search(val) {
				if(!val) {
					this.keyword = null
				}
				this.constructionPlanList = []
				this.paging.pageNum = 1
				this.getConstructionPlanArray()
			},
			getConstructionPlanArray() {
				const { pageNum, pageSize } = this.paging
				if(this.tabIndex === 0 && this.currentTypeStr === '全部') {
					this.currentTypes = [0,1]
				} else if(this.tabIndex === 1) {
					this.currentTypes = [2]
				}
				mjsConstructionInspectionRecord_list({
					currPage: pageNum,
					pageSize,
					params: {
						keyword: this.keyword,
						type: this.tabIndex === 0 ? 'dcl' : 'jl',
						projectId: uni.getStorageSync("isOwner"),
						taskStates:this.tabIndex === 0 ? ['ordered'] : undefined,
						patrolStatus:this.currentTypes,
					}
				}).then(res => {
					if (res && res.result && res.result.list) {
						this.constructionPlanList = this.constructionPlanList.concat(res.result.list)
						this.paging.total = res.result.total
					}
				})
			},
			fnAdd() {
				uni.navigateTo({
					url:`/subpackage-mjs/pages/dailyTaskList/addTask`
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		box-sizing: border-box;
		height: 100vh;
		overflow: hidden;
		/* #ifdef MP-WEIXIN */
		padding-top: 200rpx;
		/* #endif */
	}
	.conditional-acceptance-list {
		box-sizing: border-box;
		border-top: 15px solid #f5f7fa;
		background: #fff;
		font-size: 16px;
		height: 100%;
		.text-overflow {
			// white-space: nowrap;
			text-overflow: ellipsis;
			overflow: hidden;
		}
		.tab {
			line-height: 53px;
			color: #445469;
			text-align: center;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 18px;
			font-weight: 500;
			> view {
				border-bottom: 1px solid #f5f7fa;
				flex: 1;
			}
			.active {
				color: #2f80ed;
				border-color: #2f80ed;
			}
		}
		.search-content {
			height: 69px;
			padding: 0 8px 0 14px;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.search {
				display: flex;
				align-items: center;
				background: #f5f7fa;
				border-radius: 25px;
				margin-right: 6px;
				padding: 10px 12px;
				box-sizing: border-box;
				height: 44px;
				line-height: 44px;
				flex: 1;
			}
			.option {
				height: 44px;
				line-height: 44px;
				display: flex;
				align-items: center;
				justify-content: space-between;
				background: #f5f7fa;
				border-radius: 25px;
				width: 100px;
				box-sizing: border-box;
				padding: 0 14px;
				flex-shrink: 0;
				white-space: nowrap;
				view {
					color: #2f80ed;
				}
				
			}
		}
		.scroll-view {
			height: calc(100% - 15px - 54px - 69px);
			border-top: 12px solid #f5f7fa;
			box-sizing: border-box;
			padding: 0 14px;
			.item-content {
				// height: 202px;
				padding: 14px 12px 14px;
				border-bottom: 1px solid #E3E5E8;
				box-sizing: border-box;
				.title {
					height: 28px;
					line-height: 28px;
					display: flex;
					align-items: center;
					.state {
						border-radius: 0 4px 0 4px;
						font-weight: bold;
						padding: 0 4px;
						line-height: 22px;
						// margin-right: 12px;
						flex-shrink: 0;
						color: #fff;
						font-size: 14px;
						margin-right: 16rpx;
						&.gray {
							background: #e7ebf1;
							color: #434f60
						}
						&.blue {
							background: #2F80ED
						}
						&.orange {
							background: #FF8A2C
						}
						&.light-blue {
							background: #00a7e4;
						}
						&.red {
							background: #e84a4a;
						}
						&.green {
							background: #45c552;
						}
					}
					.text-overflow {
						flex: 1;
						color: #445469;
						font-weight: bold;
					}
				}
				.date {
					height: 20px;
					line-height: 20px;
					padding: 10rpx 0  0 0px;
					color: #6a819e;
					display: flex;
					font-size: 14px;
					align-items: center;
					.date-text {
						margin-left: 3px;
						white-space: nowrap;
						text-overflow: ellipsis;
						overflow: hidden;
						width: calc(100% - 20px);
					}
				}
				.label {
					line-height: 29px;
					color: #6f747b;
					font-weight: bold;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
					font-size: 14px;
				}
				.btn-content {
					display: flex;
					align-items: center;
					font-weight: 500;
					margin-top: 15px;
					text-align: center;
					font-size: 14px;
					> view {
						line-height: 34px;
						width: 100px;
						margin-right: 11px;
						border-radius: 50px;
					}
					.gray {
						color: #445469;
						background: #f5f7fa;
					}
					.blue {
						color: #fff;
						background: #2f80ed;
					}
				}
			}
		}
	}
</style>
